from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from django.http import JsonResponse

def api_root(request):
    return JsonResponse({
        "message": "ChefsHub API",
        "endpoints": {
            # 账户管理
            "accounts": "/api/accounts/",
            # 厨师管理
            "chefs": "/api/chefs/",
            # 订单管理
            "orders": "/api/orders/",
            # 支付相关
            "payments": "/api/payments/",
            # 评价系统
            "reviews": "/api/reviews/",
            # 收藏功能
            "favorites": "/api/favorites/",
            # 历史记录
            "history": "/api/history/",
            # 系统管理
            "system": "/api/system/",
            # 地址管理
            "address": "/api/address/",
            # 文件上传
            "upload": "/api/upload/",
            # 菜单管理``
            "menu": "/api/menu/",
            # 排班管理
            "schedules": "/api/schedules/",
            # 媒体文件（仅开发环境）
            "media": "/media/" if settings.DEBUG else None
        },
        "admin": "/admin/"  # 管理员入口
    })

urlpatterns = [
    path('api/', api_root, name='api-root'),  # API根入口
    path('admin/', admin.site.urls),
    path('api/accounts/', include('apps.accounts.urls')),
    path('api/chefs/', include('apps.chefs.urls')),
    path('api/orders/', include('apps.orders.urls')),
    path('api/payments/', include('apps.payments.urls')),
    path('api/reviews/', include('apps.reviews.urls')),
    path('api/favorites/', include('apps.favorites.urls')),
    path('api/history/', include('apps.history.urls')),
    path('api/system/', include('apps.system.urls')),
    path('api/address/', include('apps.address.urls')),  # 规范化
    path('api/upload/', include('apps.upload.urls')),
    path('api/menu/', include('apps.menu.urls')),
    path('api/schedules/', include('apps.schedules.urls')),
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)